﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CentroVentas.Forms.Proveedor
{
    public partial class FrmProveedorBuscar : Form
    {

        private int _idProveedor = 0;

        public int IdProveedor
        {
            get { return _idProveedor; }
            set { _idProveedor = value; }
        }

        public FrmProveedorBuscar()
        {
            InitializeComponent();
        }

        private void FrmProveedorBuscar_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = CVCore32.Class.Funciones.Proveedores.Proveedor.getProveedoresList(false);
            dataGridView1.Columns[0].Visible = false;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            dataGridView1.DataSource = CVCore32.Class.Funciones.Proveedores.Proveedor.getProveedoresList(textBox1.Text,false);
            dataGridView1.Columns[0].Visible = false;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                dataGridView1.Select();
            }
            else if (e.KeyCode == Keys.Enter)
            {
                if (dataGridView1.Rows.Count != 0)
                {
                    _idProveedor = Convert.ToInt32(dataGridView1.Rows[0].Cells[0].Value.ToString());
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
            }
        }

        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((dataGridView1.Rows.Count != 0) && (e.KeyCode == Keys.Enter))
            {
                _idProveedor = Convert.ToInt32(dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[dataGridView1.SelectedCells[0].ColumnIndex].Value.ToString());
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();

            }
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            _idProveedor = Convert.ToInt32(dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[dataGridView1.SelectedCells[0].ColumnIndex].Value.ToString());
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
    }
}
